/**
 * Created by oneminute on 7/18/14.
 */

var assert = require("assert");
var should = require("should");
var logger = require("../../lib/utils/logger");
var testutils = require("../testutils");
var lz = require("../../lib/utils/modules")();

describe("测试Demand模块。", function () {
    var demand01 = null;

    it("正常创建Demand对象。", function (done) {
        demand01 = new lz.Demand({
            id: lz.Utils.getUUID("d_"),
            uid: "u_test0001",
            description: "测试描述属性"
        });
        demand01.save(function (_err, _demand) {
            testutils.check(done, function () {
                _demand.uid.should.equal(demand01.uid);
                assert.notEqual(_demand._id, null);
            });
        });
    });

    it("根据_id正常加载Demand对象。", function (done) {
        var demand02 = new lz.Demand({_id: demand01._id});
        demand02.load(function(_err, _demand) {
            testutils.check(done, function () {
                demand02.uid.should.equal(demand01.uid);
            });
        });
    });

    it("根据AQL正常加载Demand对象。", function (done) {
        var demand03 = new lz.Demand();
        demand03.load({method: "byProp", prop: "uid", value: demand01.uid}, function(_err, _demand) {
            testutils.check(done, function() {
                demand03.uid.should.equal(demand01.uid);
            });
        });
    });

    it("根据uid使用list方法正常列出Demand对象。", function (done) {
        var demand04 = new lz.Demand({uid: demand01.uid});
        demand04.list({method: "byProp", prop: "uid"}, function(_err, _commodities) {
            testutils.check(done, function() {
                assert.equal(_commodities.length > 0, true);
                lz.Logger.info("commodities: ", _commodities);
            });
        });
    });

    it("使用delete方法删除Demand对象。", function (done) {
        demand01.delete(function(_err){
            lz.ArangoDB.getObjectById(demand01._id, function(_err, _obj) {
                testutils.check(done, function() {
                    assert.equal(_obj, null);
                });
            });
        });
    });

    after(function(done) {
        /*lz.ArangoDB.deleteObjectById(email01._id, function() {
            done();
        });*/
        done();
    });
});
